# Author: Damian 'Rush' Kaczmarek
# License: MIT
#
package ModuleManager;
use base Module;
use strict;

use Auth;

Module::define_command("load", sub {Auth::run_authed($_[0], sub { on_loadcommand(@_) }, @_ ) },
	{
		usage => "<module_name>",
		about => "Load module",
		example => "Mu"
	}
);

Module::define_command("unload", sub {Auth::run_authed($_[0], sub { on_unloadcommand(@_) }, @_ ) },
	{
		usage => "<module_name>",
		about => "Unload module",
		example => "Mu"
	}
);

Module::define_command("modinfo", \&on_modinfo,
	{
#		usage => "<module_name>",
		about => "Prints information about loaded modules",
#		example => "Mu"
	}
);

sub on_loadcommand
{
	my ($nick, $options, @args) = @_;
	return if(!@args);
	my $module = $args[0];;
	Auth::run_authed($nick, sub {Core::load_module($module) });
}

sub on_unloadcommand
{
	my ($nick, $options, @args) = @_;
	return if(!@args);
	my $module = $args[0];
	Auth::run_authed($nick, sub{ Core::unload_module($module) });
}

sub on_modinfo
{
	my ($nick, $options, @args) = @_;
	Core::send_msg("Loaded modules: " . join(", ", Core::loaded_modules()));
}
1;
